package com.example.demo.controller;


import com.example.demo.dao.SmuserRepository;
import com.example.demo.entity.Smuser;
import com.example.demo.service.SmuserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SmuserController {
    private SmuserRepository smuserRepository;
    private SmuserService smuserService;

    @Autowired
    public void setSmuserRepository(SmuserRepository smuserRepository) {
        this.smuserRepository = smuserRepository;
    }

    @Autowired
    public void setSmuserService(SmuserService smuserService) {
        this.smuserService = smuserService;
    }

    private Logger logger  =  LoggerFactory.getLogger(SmuserController.class);

    @GetMapping(value = "/getUsers")
    public List<Smuser> smuserList(){
        return smuserRepository.findAll();
    }

    @GetMapping(value = "/getUser/{userCode}")
    public List<Smuser> findOne(@PathVariable("userCode") String userCode){
        logger.debug("log进入getUsers");
        return smuserRepository.findByUserCode(userCode);
    }

    @PostMapping(value = "/addUser")
    public Smuser addUser(Smuser smuser) {
        logger.debug("log进入addUser"+smuser);
        return smuserService.addUser(smuser);
    }
}
